package com.example.rabbitdemo.message;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DlxConfig {

    @Bean
    public Queue myBusinessQueue() {
        return QueueBuilder.durable("my.business.queue")
                .withArgument("x-dead-letter-exchange", "my.dlx.exchange") // 指定死信交换机
                .withArgument("x-dead-letter-routing-key", "dlx.key")      // 死信路由键
                .withArgument("x-message-ttl", 10000)                      // 可选：消息TTL
                .build();
    }

    @Bean
    public DirectExchange dlxExchange() {
        return new DirectExchange("my.dlx.exchange", true, false);
    }

    @Bean
    public Queue dlxQueue() {
        return QueueBuilder.durable("my.dlx.queue").build();
    }

    @Bean
    public Binding dlxBinding() {
        return BindingBuilder.bind(dlxQueue()).to(dlxExchange()).with("dlx.key");
    }
}